﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Configuration;
using System.Web;
using System.Data;

namespace DaoYou.Web.Guider.Account
{
    public class PageHelper
    {
        public PageHelper()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }


        private static PageHelper _instance = null;
        private static object _synObj = new object();

        HttpCookie cookie = null;


        public static PageHelper Current
        {
            get
            {
                if (_instance == null)
                {
                    lock (_synObj)
                    {
                        if (_instance == null)
                        {
                            _instance = new PageHelper();
                            return _instance;
                        }
                    }
                }

                return _instance;
            }
        }


        public void SetCookie(string UserName, int UserType)
        {
            try
            {
                cookie = new HttpCookie(ConfigurationManager.AppSettings["COOKIE_KEY_USER"] as string);
                DateTime dtNow = DateTime.Now;
                string time = ConfigurationManager.AppSettings["COOKIE_TIME"].ToString();
                cookie.Expires.AddMinutes(double.Parse(time));

                cookie.Values["name"] = UserName;
                cookie.Values["type"] = UserType.ToString();

                HttpContext.Current.Response.Cookies.Set(cookie);
                HttpContext.Current.Response.AppendCookie(cookie);
            }
            catch (Exception ex)
            {
                //Logger.WriteLog(ex.Message);

                throw ex;
            }
        }
    }
}
